//
//  Team9ExpertDiscussCell.m
//  Team9Project
//
//  Created by 朱嘉祺 on 15/10/16.
//  Copyright © 2015年 apple. All rights reserved.
//

#import "Team9ExpertDiscussCell.h"
#import "Team9JQHeader.h"
#import "Team9ExpertDiscussModel.h"

@interface Team9ExpertDiscussCell ()

@property(nonatomic ,strong)Team9BaseView *myBackView;
@property(nonatomic, strong) UIImageView *picImageView;
@property(nonatomic, strong)Team9BaseLabel *titleLabel;
@property(nonatomic, strong) Team9BaseLabel *replyLabel;
@property(nonatomic, strong) Team9BaseLabel *lastReplyLabel;

@end
@implementation Team9ExpertDiscussCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
//        [self test];
    }
    return self;
}
- (void)test{
    self.picImageView.image = [UIImage imageNamed:@"test"];
    if (random()%2) {
            self.titleLabel.text = @"15042341680#15042341680#15042341680#15042341680#15042341680#15042341680#v15042341680#15042341680#15042341680#15042341680#15042341680#15042341680#15042341680#15042341680#15042341680#";
    } else {
        self.titleLabel.text = @"15042341680";
    }
    self.lastReplyLabel.text = @"123456";
 
}
- (void)createView{
 
    self.contentView.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1];
    
    self.myBackView = [[Team9BaseView alloc] init];
    [self.contentView addSubview:_myBackView];
    self.myBackView.layer.cornerRadius = 5;
    self.myBackView.layer.masksToBounds = YES;
    
    self.picImageView = [UIImageView new];
    [self.myBackView addSubview:_picImageView];
    self.picImageView.layer.cornerRadius = 5;
    self.picImageView.layer.masksToBounds = YES;

    self.titleLabel = [[Team9BaseLabel alloc] init];
    [self.myBackView addSubview:_titleLabel];
    self.titleLabel.numberOfLines = 2;
    
    self.replyLabel = [[Team9BaseLabel alloc] initWith:LableColorTypeRedCyan];
    [self.myBackView addSubview:_replyLabel];
    
    self.lastReplyLabel = [[Team9BaseLabel alloc] init];
    [self.myBackView addSubview:_lastReplyLabel];
    self.lastReplyLabel.numberOfLines = 3;
    self.lastReplyLabel.font = [UIFont systemFontOfSize:10 * WIDTH / 375];
    self.replyLabel.font = [UIFont systemFontOfSize:14 * WIDTH / 375];
    
    [self p_contraints];
}
- (void)p_contraints{
    [self.myBackView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self).insets(UIEdgeInsetsMake(10, 10, 10, 10));
    }];
    [self.picImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.bottom.equalTo(self.myBackView);
        make.width.equalTo(self.picImageView.mas_height);
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.picImageView.mas_right).offset(10);
        make.top.equalTo(self.myBackView).offset(10);
        make.right.equalTo(self.myBackView).offset(-10);
    }];
    
    UIImageView *talkImage = [UIImageView new];
    talkImage.image = [UIImage imageNamed:@"iconfont-message"];
    [self.myBackView addSubview:talkImage];
//    talkImage.backgroundColor = [UIColor redColor];
    
    [talkImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lastReplyLabel);
        make.width.height.equalTo(@(12 * WIDTH / 375));
        make.left.equalTo(self.titleLabel);
    }];
    
    [self.lastReplyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(10);
        make.right.equalTo(self.titleLabel);
        make.left.equalTo(talkImage.mas_right).offset(5);
    }];
    
    [self.replyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.titleLabel);
        make.bottom.equalTo(self.myBackView).offset(-10);
    }];
}
- (void)setModel:(Team9ExpertDiscussModel *)model
{
    if (_model != model) {
        _model = model;
    }
    self.replyLabel.text = [NSString stringWithFormat:@"回应 %@", self.model.reply_count];
    self.lastReplyLabel.text = self.model.latest_content;
    self.titleLabel.text = self.model.title;
    [self.picImageView sd_setImageWithURL:[NSURL URLWithString:self.model.pic] placeholderImage:[UIImage imageNamed:@"333"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        
    }];
}
- (void)layoutSubviews{
    [super layoutSubviews];
//    NSLog(@"%g", self.lastReplyLabel.frame.size.height);
}
@end
